/**
 * @file 审计通用组件
 * @date 2025/11/14 16:25:10
 * @author lyqjob@yeah.net
 */

import { memo, useMemo } from 'react';
import { Descriptions } from 'antd';
import dayjs from '@/utils/dayjs.js';

const Audit = memo((props) => {
    const { data } = props;

    // 使用 useMemo 优化 items 计算，避免每次渲染都重新计算
    const items = useMemo(() => {
        if (!data) {
            return [];
        }

        return [
            {
                key: 'created_at',
                label: '创建时间',
                children: data.created_at ? dayjs(data.created_at).format('YYYY-MM-DD HH:mm:ss') : '-'
            },
            {
                key: 'create_by_name',
                label: '创建人',
                children: data.create_by_name || '-'
            },
            {
                key: 'updated_at',
                label: '修改时间',
                children: data.updated_at ? dayjs(data.updated_at).format('YYYY-MM-DD HH:mm:ss') : '-'
            },
            {
                key: 'update_by_name',
                label: '修改人',
                children: data.update_by_name || '-'
            }
        ];
    }, [data]);

    return (
        <Descriptions
            column={4}
            size="small"
            items={items}
        />
    );
});

export default Audit;